using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPDetailsImportService
    {
        ISession session;

        public MRPDetailsImportService(ISession session)
        {
            this.session = session;
        }
        public MRPDetailsImportService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpdetailsimport(MRPDetailsImport mrpdetailsimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpdetailsimportX);
            tx.Commit();
        }

        public void UpdateMrpdetailsimport(MRPDetailsImport mrpdetailsimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpdetailsimportX);
            tx.Commit();
        }

        public void DeleteMrpdetailsimport(MRPDetailsImport mrpdetailsimportX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpdetailsimportX);
            tx.Commit();
        }

        public IList<MRPDetailsImport> GetAllMrpdetailsimport(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPDetailsImport");
            IList<MRPDetailsImport> list = query.List<MRPDetailsImport>();
            if (evict)
            {
                foreach (MRPDetailsImport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPDetailsImport GetAllMrpdetailsimportByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPDetailsImport as c where c.Detailsimportid= :x");
            query.SetString("x", id);
            MRPDetailsImport s = (MRPDetailsImport)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPDetailsImport> GetMrpdetailsimportByQuery(IQuery query, Boolean evict)
        {
            IList<MRPDetailsImport> list = query.List<MRPDetailsImport>();
            if (evict)
            {
                foreach (MRPDetailsImport s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
